n = input()
m = 0
k = 0
if 999 <int(n)< 10000:
    for left in range(4):
        for right in range(left, 4):
            num = int(n[left:right+1])
            for i in range(2, num//2+1):
                if(num % i == 0):
                    k = k + 1
            if k == 0:
                if m<num and num!=1:
                    m = num
    if m != 0:
        print(m)
    else:
        print(0)
else:
    print(0)

